{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "likely-departure",
   "metadata": {},
   "source": [
    "## 导入依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "regulation-wellington",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jupyter environment detected. Enabling Open3D WebVisualizer.\n",
      "[Open3D INFO] WebRTC GUI backend enabled.\n",
      "[Open3D INFO] WebRTCWindowSystem: HTTP handshake server disabled.\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "import numpy as np\n",
    "# 阿凯机器人工具箱\n",
    "from kyle_robot_toolbox.robot_arm.arm5dof_uservo import Arm5DoFUServo"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "distinct-sport",
   "metadata": {},
   "source": [
    "## 机械臂创建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "reserved-intake",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建机械臂\n",
    "arm = Arm5DoFUServo(config_folder=\"./config\", \\\n",
    "                    is_init_pose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "muslim-oriental",
   "metadata": {},
   "source": [
    "## 关节控制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "smoking-motion",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arm.set_joint_angle_list([0, -math.pi/2, 0, 0, 0, math.pi/4], is_wait=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "olive-batch",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arm.set_joint_angle_list([0, -3*math.pi/4, math.pi/3, math.pi/2, 0, 0], is_wait=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "159e40a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[   0. -135.   60.   90.    0.    0.]\n"
     ]
    }
   ],
   "source": [
    "print(np.degrees([0, -3*math.pi/4, math.pi/3, math.pi/2, 0, 0]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "featured-cardiff",
   "metadata": {},
   "source": [
    "## 关节控制Minimum Jerk轨迹规划"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "skilled-henry",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "完成动作\n"
     ]
    }
   ],
   "source": [
    "arm.set_joint_angle_list_soft([math.pi/2, -math.pi/2, math.pi/4, 0], T=1.0)\n",
    "arm.set_joint_angle_list_soft([-math.pi/2, -math.pi/2, math.pi/3, math.pi/3], T=1.5)\n",
    "arm.set_joint_angle_list_soft([0, -3*math.pi/4, math.pi/2, math.pi/3], T=1.0)\n",
    "arm.set_joint_angle_list_soft([0, -math.pi/2, 0, 0], T=1.0)\n",
    "arm.set_joint_angle_list_soft([0, -math.pi/3, 0, 0], T=1.0)\n",
    "arm.set_joint_angle_list_soft([math.pi/2, -math.pi/2, 0, 0], T=1.0)\n",
    "arm.home()\n",
    "print(\"完成动作\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
